package com.handinfo.android.game;

import android.graphics.Color;

import com.handinfo.android.core.graphics.DWFont;
import com.handinfo.android.core.graphics.DWGraphics;
import com.handinfo.android.game.item.Item;

public class Cell implements IIcon,IShortcutObject
{

	public static final byte TYPE_COLUMN_ROLEBAG = 0;//角色背包栏
	public static final byte TYPE_COLUMN_EQUIP = 1;//装备位栏
	public static final byte TYPE_COLUMN_WAREHOUSE = 2;//仓库栏
	public static final byte TYPE_COLUMN_SHOP = 3;//摆摊栏

	//背包栏子类型
	public static final byte SIZE_ROLEBAG_COLUMN = 5;
	public static final byte INDEX_ROLEBAG_ALL = 0; //所有背包物品
	public static final byte INDEX_ROLEBAG_EQUIP = 1;//装备
	public static final byte INDEX_ROLEBAG_CONSUME = 2;//消耗
	public static final byte INDEX_ROLEBAG_GEM = 3;//宝石
	public static final byte INDEX_ROLEBAG_OTHER = 4;//其他

	public int m_column_type;// 标识那栏的格子
	public int m_index; //当前格子索引
	public Item m_item;//当前栏引用的道具
	public boolean m_selected;//是否被选中

	public Cell()
	{

	}

	public Cell(byte type, int index)
	{
		m_index = index;
		m_column_type = type;
	}

	public Cell(Item item, byte type, int index)
	{
		m_item = item;
		m_column_type = type;
		m_index = index;
	}

	public void setCell(Item item, byte type, int index)
	{
		m_item = item;
		m_column_type = type;
		m_index = index;
	}

	public Cell Clone()
	{
		Cell cell = new Cell();
		cell.m_column_type = m_column_type;
		cell.m_index = m_index;
		if(m_item != null){			
			cell.m_item = m_item.Clone();
		}else{
			cell.m_item = null;
		}
		return cell;
	}

	public void setCell(int index)
	{
		m_index = index;
	}

	public void setCell(Item item, byte type, int index, int recordIndex)
	{
		m_item = item;
		m_column_type = type;
		m_index = index;
	}

	public void dispose()
	{
		m_item = null;
	}

	public void drawIcon(DWGraphics g, int x, int y, int w, int h, int anchor)
	{
		if (m_item != null){
			m_item.drawIcon(g, x, y, w, h, anchor);
		}
		drawNumber(g, x, y, w, h);
	}

	public void drawIcon(DWGraphics g, int x, int y, int w, int h, float scaleX, float scaleY, int anchor)
	{
		if (m_item != null){			
			m_item.drawIcon(g, x, y, w, anchor, scaleX, scaleY, anchor);
		}
	}
	
    public void drawNumber(DWGraphics g, int x, int y,int w,int h){
    	if (m_item != null && m_item.m_num > 1) {
    		float tempX = x - (w>>1);
    		float tempY = y + ((h >> 1) - DWFont.getDefaultFont().getHeight());
    		String temp = ""+ m_item.m_num ;
			//Tools.debugPrintln("name="+m_item.m_name+";num="+m_item.m_num +";y="+y+";x="+x);
			g.drawString(temp, Color.WHITE, tempX, tempY, 0);
		}
    }

	public boolean doShortcutAction()
	{
		if(m_item != null){
			return m_item.doShortcutAction();
		}
		return true;
	}

	public boolean doShortcutAction(Role role)
	{
		if (m_item != null) {
			return m_item.doShortcutAction(role);
		}
		return true;
	}
}
